<?php

/**
 * Created by PhpStorm.
 * User: wu
 * Date: 2017/4/20
 * Time: 18:16
 */
class C_product_detail
{
    private $resource;

    private $call_items;

    private $back_items;

    private $resource_id;

    public function __construct()
    {
        $this->resource = 'C_Product';

        $this->call_items = array(
            "t" => time(),
            "k" => "",
            'uid' => '',
            'v' => API_VERSION,
            "enterpriseId" => "",
            "channelId" => "",
            "userType" => ""
        );

        $this->back_items = array(
            "id" => "",                         //产品ID,
            "enterprise_id" => "",              //企业id,
            "brand_id" => "",                   //分类id,
            "name" => "",                       //产品名称,
            "icon_url" => "",                   //产品缩略图片,
            "repertory_warning" => "",          //库存预警值,
            "individual_packing" => "",         //单品包装规格
            "mass_packing" => "",               //外包装规格
            "remark" => "",                     //产品备注
            "insert_time" => "",                //创建时间
            "is_del" => "",                     //是否有效
            "rich_text_url" => "",              //产品详情链接
            "brandname" => "",                  //分类名称
            "channel_price" => "",              //渠道价格
            "collect_stock" => "",              //当前库存
            "stock_warning" => "",              //是否库存预警
            "sku_info" => array(),              //多规格产品
            "scroller_imgs" => array(),         //轮播图
            "detail_imgs" => array(),           //缩略图
            "collection_status" => 0,           //是否收藏
            "activity_info" => array(),         //活动信息
        );
    }

    public function set_call_items($obj = array())
    {
        foreach ($this->call_items as $key => $val) {
            if (isset($obj[$key])) {
                $this->call_items[$key] = $obj[$key];
            }
        }
        $this->call_items['k'] = md5($obj['password'] . $this->resource_id.$this->call_items['t']);
        return $this->_get_url();
    }

    public function set_back_items($data = array())
    {
        foreach ($this->back_items as $key => $val) {
            if (isset($data[$key])) {
                $this->back_items[$key] = $data[$key];
            }
        }
    }

    public function set_resource_id($id)
    {
        $this->resource_id = $id;
        return $this->_get_url();
    }

    public function get_call_items()
    {
        return $this->call_items;
    }

    public function get_back_items()
    {
        return $this->back_items;
    }

    public function get_resource_id()
    {
        return $this->resource_id;
    }

    private function _get_url()
    {
        if ($this->resource_id) {
            return $this->resource . '/' . $this->resource_id . '/';
        } else {
            return $this->resource . '/';
        }
    }
}